import {
  getArticle
} from '../../../api/home'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    lsLoading: false,
    query: {
      channelId: 409,
      pageNo: 1,
      pageSize: 12
    },
    text: "上拉加载更多",
    dataList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.initArticle()
  },
  async initArticle() {
    let result = await getArticle(this.data.query)
    if (result.statusCode == 200) {
      let list = result.data.data.list
      console.log(list);

      list.forEach(item => {
        this.data.dataList.push({
          src: item.listView,
          title: item.name,
        })
      });
      this.setData({
        dataList: this.data.dataList,
        lsLoading: false,
        text: '上拉加载更多',
      })

    }
  },
  scrollToLower() {
    if (!this.data.lsLoading) {
      if (this.data.query.pageNo >= 4) {
        this.setData({
          text: '我也是有底线的',
        })
      }else{
        this.setData({
          lsLoading: true,
          text: '加载中...',
          'query.pageNo': this.data.query.pageNo + 1,
        })
        this.initArticle()
      }
     
    }

  }

})